TINYMCE_DEFAULT_CONFIG = {
    "theme": "silver",
    "height": 500,
    "menubar": "file edit format",
    "language": "zh_CN",
    "plugins": "advlist,anchor,autolink,autosave,charmap,code,codesample,emoticons,fullpage,"
               "fullscreen,hr,image,imagetools,insertdatetime,link,media,preview,print,searchreplace,"
               "spellchecker,table,textcolor,wordcount",
    "toolbar": "formatselect | bold italic backcolor | alignleft aligncenter "
               "alignright alignjustify hr | bullist numlist outdent indent | "
               "table link image media codesample insertdatetime removeformat preview | "
               "charmap anchor emoticons | fullscreen  preview print searchreplace wordcount",
    "images_upload_url": "/upload/",
    "file_picker_types": 'file image media',
    # "images_upload_handler": """function (blobInfo, success, failure, progress) {
    #     console.log(failure)
    #     var xhr, formData;
    #     xhr = new XMLHttpRequest();
    #     xhr.withCredentials = false;
    #     xhr.open('POST', '/upload/');
    #     xhr.upload.onprogress = function(e){
    #         progress(e.loaded / e.total * 100);
    #     }
    #     xhr.onload = function() {
    #         var json;
    #         if (xhr.status == 403) {
    #             failure('HTTP Error: ' + xhr.status, { remove: true });
    #             return;
    #         }
    #         if (xhr.status < 200 || xhr.status >= 300 ) {
    #             failure('HTTP Error: ' + xhr.status);
    #             return;
    #         }
    #         json = JSON.parse(xhr.responseText);
    #         if (!json) {
    #             failure('Invalid JSON: ' + xhr.responseText);
    #             return;
    #         }
    #         if (json.error) {
    #             failure('Invalid JSON: ' + json.message);
    #             return;
    #         }
    #         success(json.url);
    #     };
    #     xhr.onerror = function () {
    #         failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
    #     }
    #     formData = new FormData();
    #     formData.append('file', blobInfo.blob(), blobInfo.filename());
    #     xhr.send(formData);
    # }""",
    "file_picker_callback": """function (callback, value, meta) {
        //文件分类
        var filetype = '.pdf, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .mp3, .mp4';
        //后端接收上传文件的地址
        var upurl = '/upload/';
        //为不同插件指定文件类型及后端地址
        switch (meta.filetype) {
            case 'image':
                filetype = '.jpg, .jpeg, .png, .gif';
                break;
            case 'media':
                filetype = '.mp3, .mp4';
                break;
            case 'file':
            default:
        }
        //模拟出一个input用于添加本地文件
        var input = document.createElement('input');
        input.setAttribute('type', 'file');
        input.setAttribute('accept', filetype);
        input.click();
        input.onchange = function () {
            var file = this.files[0];
            // 图片上传方式
            var xhr, formData;
            xhr = new XMLHttpRequest();
            xhr.withCredentials = false;
            xhr.open('POST', upurl);
            xhr.onload = function () {
                var json;
                if (xhr.status == 403) {
                    alert('HTTP Error: ' + xhr.status, {remove: true});
                    return;
                }
                if (xhr.status < 200 || xhr.status >= 300) {
                    alert('HTTP Error: ' + xhr.status);
                    return;
                }
                json = JSON.parse(xhr.responseText);
                if (!json) {
                    alert('Invalid JSON: ' + xhr.responseText);
                    return;
                }
                if (json.error) {
                    alert('Invalid JSON: ' + json.message);
                    return;
                }
                callback(json.location, json.data);
            };
            formData = new FormData();
            formData.append('file', file, file.name);
            xhr.send(formData);
        }
    }""",

}